if (!window.Vue) {
  throw '请引入Vue'
}

// 注册组件
Vue.component('ui-form', {
  template: '#form',
  props: { title: String, options: Object, model: Object, value: Object },
  data: function() {
    return {
      form: {
        select: '',
        radio: '',
        tags: [],
        textarea: ''
      }
    }
  },
  watch: {
    form: {
      immediate: true,
      deep: true,
      handler(value) {
        this.$emit('input', value)
      }
    }
  },
  computed: {
    isMultiple() {
      return this.options.tag ? this.options.tag.multiple : false
    }
  },
  methods: {
    handleToggleTag: function(tag) {
      var index = this.form.tags.findIndex(function(value) {
        return value === tag.value
      })
      if (index === -1) {
        if (this.isMultiple) {
          this.form.tags.push(tag.value)
        } else {
          this.form.tags = [tag.value]
        }
      } else {
        this.form.tags.splice(index, 1)
      }
    }
  },
  created() {
    this.form = Object.assign({}, this.form, this.value)
  }
})

// 表单配置
const formList = [
  {
    title: '服务评价',
    options: {
      radio: {
        model: 'radio',
        values: fweav
      },
      tag: {
        multiple: true,
        model: 'tag',
        values: fwtag
      },
      textarea: {
        model: 'textarea'
      }
    }
  },
  {
    title: '菜品评价',
    options: {
      radio: {
        model: 'radio',
        values: cpeva
      },
      tag: {
        model: 'tag',
		multiple: true,
        values: cptag
      },
      textarea: {
        model: 'textarea'
      }
    }
  }
]

const vm = new Vue({
  data: {
    formList: formList,
    model: {
      num: '',
      code: '',
      forms: [
        { radio: '46', tags: [], textarea: '点击上方标签，为我们提供您本次就餐更全面的评价，可以帮助更多小伙伴哦！' },
        { radio: '56', tags: [], textarea: '点击上方标签，为我们提供您本次就餐更全面的评价，可以帮助更多小伙伴哦！' }
      ]
    }
  },
  methods: {
    handleSubmit() {
      // console.log(this.model)
      // console.log(JSON.stringify(this.model))
      $.post('/home/index/post.html',{data:JSON.stringify(this.model)},function (res) {
        console.log(res);

      })
    }
  }
}).$mount('#app')
